import axios from "axios";
import {ElMessage} from "element-plus";

const service = axios.create({
    baseURL:'/nist',
    timeout:5000
})

service.interceptors.request.use((config)=>{
    config.headers['apiKey'] = 'd31fd7c8-b80a-41ca-9450-3d7e2f1786e2'
    if ('get'.includes(config.method?.toLowerCase() as string))
        config.params = {'cveId':config.cveId}
    return config
},(error)=>{
    Promise.reject(error)
})

service.interceptors.response.use((response)=>{
    // console.log(response.data)
    return response.data
},(error)=>{
    ElMessage.error({
        message:error,
        duration:2*1000
    })
    return Promise.reject(error)
})

export default function nistReq(config){
    return service({...config})
}

